{extends file="./main.tpl"}
{block name=head}
<script type="text/javascript">
$(document).ready(function()
{
  setVoucherNo();
  $(".account").blur(function()
  {
    if($(".account:last").val() != '' && $(".account:last").val() > 0)
    {
      $("#one").clone(true).appendTo("#mainDiv")
      .find('input[type="text"]').val('').end()
      .find('select[option=""]').val('');
    }
  });
});
function setVoucherNo()
{
  var dayExtra    = $('#fromDateDay').val();
  var monthExtra  = $('#fromDateMonth').val();
  var yearExtra   = $('#fromDateYear').val();
  var voucherType = $('.voucherType').val();
	var fullDate = yearExtra+'-'+monthExtra+'-'+dayExtra;
	var dataString = "fullDate=" + fullDate + "&voucherType=" + voucherType;
  $.ajax(
  {
    type: "GET",
    url: "setVoucherNo.php",
    data: dataString,
    success:function(data)
    {
      $('#getVoucherNo').val(data);
    }
  });
}
function setLoan(thisObj)
{
	var row        = $(thisObj).parents('.amtRow');
	var drAccountId  = $(row).find('.drAccountId').val() != '' ? $(row).find('.drAccountId').val() : 0;
	var dataString = "drAccountId=" + drAccountId;
  $.ajax(
  {
    type: "GET",
    url: "setLoan.php",
    data: dataString,
    success:function(data)
    {
      row.find('.getLoanNo').html(data);
    }
  });
}
function newWindow()
{
	if($('#payment').val() == 'Journal')
	{
    window.location.replace('transactionDrCr.php?payment='+$('#payment').val(), '_self');
	}
}
function setAmountTotal()
{
  var totalAmount = 0;
  
  $('.amount').each(function(i)
  {
    amount = $(this).val();
    if(!isNaN(amount))
    {
      totalAmount += Number(amount);
    }
  });
  $('#totalAmount').val(totalAmount.toFixed(2));
}
</script>
{/block}
{block name=body}
<form name="" id="" action="{$smarty.server.PHP_SELF}" method="POST" onsubmit="return confirm('DO You Want To Submit !!!!!')";>
  <table cellpadding="2" cellspacing="0" border="1" align="center">
    <tr>
      <td colspan="4" align="center" style="background:#EBF5FF;">
      	<h1><font size="5px">Transaction</font></h1>
      </td>
    </tr>
    <tr>
      <th>Voucher</th>
      <th>Date</th>
      <th>Account</th>
      <th>Voucher No.</th>
    </tr>
    <tr>
      <td>
      	<select name="voucherType" id="payment" class="voucherType" onchange="newWindow(); setVoucherNo();" REQUIRED AUTOFOCUS />
        	<option value="">-- Select Voucher --</option>
        	{html_options values=$paymentValuesArr output=$paymentOutputArr selected=$payment}
        </select>
      </td>
      <td onchange="setVoucherNo();">
        {html_select_date day_extra="id=\"fromDateDay\"" month_extra="id=\"fromDateMonth\"" year_extra="id=\"fromDateYear\"" prefix='transDate' field_order="DmY" month_format="%m" start_year='-5' end_year='+5' day_value_format="%02d"}
      </td>
      <td>
      	<select name="crAccountId" class="account">
        	<option value="0">-- Select Account--</option>
        	{html_options values=$mainAccArray.accountId output=$mainAccArray.accountName}
        </select>
      </td>
      <td><input type="text" name="voucherNo" id="getVoucherNo" size="15" READONLY /></td>
    </tr>
    </table>
    </br></br></br>
    <table cellpadding="2" cellspacing="0" border="1" align="center">
    <tbody id="mainDiv">
    <tr>
      <td colspan="4" align="center" style="background:#EBF5FF;">
      	<h1><font size="5px">Transaction Detail</font></h1>
      </td>
    </tr>
    <tr>
      <th>Account Name</th>
      <th>Loan</th>
      <th>Loan/Interest</th>
      <th>Amount</th>
    </tr>
    <tr  id="one" class="amtRow">
      <td align="center">
        <select name="drAccountId[]" class="account drAccountId" onchange="setLoan(this);">
        	<option value="0">-- Select Account --</option>
        	{html_options values=$accArray.accountId output=$accArray.accountName}
        </select>
      </td>
      <td align="center">
        <select name="loanId[]" class="getLoanNo">
        	<option value="0">-- Select Loan --</option>
        </select>
      </td>
      <td align="center">
        <select name="loanOrInterest[]">
        	<option value="0">-- Select Loan/Interest --</option>
        	{html_options values=$loanInterestArray output=$loanInterestArray}
        </select>
      </td>
      <td align="center">
        <input type="text" name="drAmount[]" class="amount textAlignRight twoToFixed" size="15" onkeyup="setAmountTotal();" />
      </td>
    </tr>
  </tbody>
  <tr>
    <th colspan="3">Total</th>
    <td align="center"><input type="text" name="crAmount" class="textAlignRight" id="totalAmount" size="15" /></td>
  </tr>
  <tr>
  	<td colspan="3">
      <input type="submit" name="submitBtn" value="Save" />
    </td>
  </tr>
  </table>
</form> 
{/block}